<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>创客手机网站</title>
  <script src="/wap/js/flexible.js"></script>
  <script src="/wap/js/jquery-3.2.1.min.js"></script>
  <script src="/wap/js/util.js"></script>
  <link rel="stylesheet" href="/wap/css/style.css">
</head>
<body>
<div id="modify">
  <div id="formInput" style="width: 95%;margin: 0 auto">
    <input type="hidden" name="_token" value="{{csrf_token()}}">
    <div class="input">
      <div class="input__left">手机号码</div>
      <div class="input__right">
        <input type="text" id="mobile" placeholder="请输入手机号码" maxlength="11">
      </div>
    </div>
    <div class="input">
      <div class="input__left">原密码</div>
      <div class="input__right">
        <input type="password" id="pwd_old" placeholder="请输入原密码">
      </div>
    </div>
    <div class="input">
      <div class="input__left">新密码</div>
      <div class="input__right">
        <input type="password" id="pwd_new" placeholder="请输入新密码" />
      </div>
    </div>
    <div class="input">
      <div class="input__left">确认新密码</div>
      <div class="input__right">
        <input type="password" id="pwd_confirm" placeholder="请再次确认新密码"/>
      </div>
    </div>
    <div class="form__btn">完成</div>
  </div>
</div>
<script>
    $(function(){
        $('.input').bind('input propertychange', function() {
            var isTrue = $('#mobile').val()!='' && $('#pwd_new').val()!='' &&  $('#pwd_old').val()!='' &&  $('#pwd_confirm').val()!=''?true:false;
            if(isTrue)
                $('.form__btn').addClass('bg-e60012');
            else
                $('.form__btn').removeClass('bg-e60012');
        });
        $('.form__btn').click(function() {
            var mobile = $('#mobile').val();
            var pwd_new = $('#pwd_new').val();
            var pwd_old = $('#pwd_old').val();
            var pwd_confirm = $('#pwd_confirm').val();
            var csrf_token = $('input[name="_token"]').val();
            var isTrue = mobile!='' && pwd_new!='' &&  pwd_old!='' &&  pwd_confirm!=''?true:false;
            if(!isTrue){
                toast('数据不完整',2000);
                return false;
            }
            $.ajax({
                type: 'post',
                url: '{{ route('wap.index.changePassword') }}',
                data: {'mobile':mobile,'pwd_new':pwd_new,'pwd_old':pwd_old,'pwd_confirm':pwd_confirm,'_token':csrf_token},
                dataType: "JSON",
                async: false,
                success: function (res) {
                    if(res.s=='FAIL'){
                        toast(res.data,2000);
                    }else{
                        toast('修改成功！',2000);
                        window.location.href = '/wap/index/login';
                    }
                },
                error: function (res) {
                    console.log(res, 'error');
                }
            });
        })
    })
</script>
</body>
</html>

<script>
  $('.login__form__btn').on('click', function() {
      var mobile = $('input[name="mobile"]').val();
      var password = $('input[name="password"]').val();
      var csrf_token = $('input[name="_token"]').val();
      if(mobile == ''){
          toast('未输入手机号！',1000);
          $('input[name="mobile"]').focus();
          return false;
      }
      if(password == ''){
          toast('未输入密码！',1000);
          $('input[name="password"]').focus();
          return false;
      }
      $.ajax({
          type: 'post',
          url: '{{ route('wap.index.ajaxLogin') }}',
          data: {'mobile':mobile,'password':password,'_token':csrf_token},
          dataType: "JSON",
          async: false,
          success: function (res) {
              if(res.status=="FAIL"){
                  toast(res.message,2000);
              }else{
                  window.location.href = res.url;
              }
          },
          error: function (res) {
              console.log(res, 'error');
          }
      });
  })
</script>